<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html style="height: auto; min-height: 100%;">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>天津市西青医院满意度调查问卷</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<%=basePath%>bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<%=basePath%>dist/css/skins/_all-skins.min.css">
    <!-- Validator style -->
    <link href="<%=basePath %>bootstrap/bootstrapvalidator/dist/css/bootstrapValidator.min.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-editable.css" rel="stylesheet">
    <link href="<%=basePath %>bootstrap/bootstrap-table/dist/bootstrap-table.css" rel="stylesheet"/>
    <link href="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.css" rel="stylesheet"/>
</head>
<body class="skin-blue sidebar-mini" style="height: auto; min-height: 100%;">
<div class="wrapper" style="height: auto; min-height: 100%;">
    <!-- header头部页面 -->
    <jsp:include page="../commend/top.jsp"/>
    <!-- Left side column. contains the logo and sidebar -->
    <jsp:include page="../commend/left.jsp"/>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" style="min-height: 800px;">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>

                <small>填写调查问卷</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li class="active">填写调查问卷</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Info boxes -->
            <!-- Main row -->
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">问题列表</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body ">
                            <div class="row ">
                                <div class="col-md-12" style="height: 300px">
                                    <table
                                            id="questiontable"
                                            data-toggle="table"
                                            data-url="<%=basePath%>/question/selectQuestionByPaperId?paperId=${paperId}"
                                            style="font-size: 100%"
                                    >
                                        <thead>
                                        <tr>
                                            <th data-field="soreid" data-formatter="questionsortformat">序号</th>
                                            <th data-field="content" >问题</th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- ./box-body -->
                        <div class="box-footer">
                            <div class="row">

                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.box-footer -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">科室评价</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body ">
                            <div class="row ">
                                <div class="col-md-12" >
                                    <div id="toolbar" class="btn-group">
                                        <button id="btn_save" type="button" class="btn  btn-primary" data-toggle="modal" data-target="#modalTable" style="margin-right: 10px">
                                            提交调查问卷
                                        </button>

                                    </div>
                                    <table
                                            id="evaltable"
                                            data-toggle="table"
                                            data-toolbar="#toolbar"
                                            data-url="<%=basePath%>/deptMapper/findEvalDeptListByDeptId?paperId=${paperId}"
                                            style="font-size: 100%"
                                    >
                                        <thead>
                                        <tr>
                                            <th data-field="name">科室名称</th>
                                            <c:set var="questionno" value="1" />
                                            <c:forEach items="${questionList}" var="questionitem">
                                                <c:set var="index" value="${index+1}" />
                                                <th data-field="question${questionitem.id}" data-editable="true"  data-editable-type="select" data-editable-title="问题${index}"
                                                    data-editable-source="<%=basePath%>/gradeScore/selectAllGradeScores" >问题${index}</th>
                                            </c:forEach>
                                            <th data-field="context" data-editable="true" data-editable-type="text" data-editable-title="说明">说明</th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- ./box-body -->
                        <div class="box-footer">
                            <div class="row">

                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.box-footer -->
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <!-- footer-->
    <jsp:include page="../commend/footer.jsp"/>
</div>

<!-- jQuery 3 -->
<script src="<%=basePath %>bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<%=basePath %>bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath %>bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="<%=basePath %>dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="<%=basePath %>dist/js/demo.js"></script>
<!-- Validator 3.3.7 -->
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/bootstrapValidator.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrapvalidator/dist/js/language/zh_CN.js"></script>
<!-- bootstrap-table -->
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-editable.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-table.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/extensions/x-editable/bootstrap-table-editable.min.js"></script>
<script src="<%=basePath %>bootstrap/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- bootbox -->
<script src="<%=basePath %>bootstrap/bootbox/bootbox.min.js"></script>
<script src="<%=basePath %>bootstrap/bootoast/dist/bootoast.min.js"></script>
<script src="<%=basePath %>bootstrap/commend/initcommend.js"></script>

<script>
    $(function() {
        $('#evaltable').bootstrapTable()
        $("#btn_save").on('click',function () {
            submitEval()
        })
    })
    
    function questionsortformat(value, row, index) {
        return index+1;
    }

    /**
     * 提交满意度调查问卷
     */
    function submitEval() {
        var notFullTure = false;
        var oksubmit = true;
        var tabledata = $("#evaltable").bootstrapTable("getData")
        $("#btn_save").attr("disabled",true);
        $(tabledata).filter(function () {
            var row = this;
            $.each(row, function(i) {
                if(i.indexOf('question')>-1){
                    if (row[i] != 20){
                        notFullTure = true;
                    }
                    if (row[i] == 10 && row.context == '如不满意需填写说明'){
                        bootbox.alert(row.name+'有不满意评价必须填写说明');
                        oksubmit = false;
                        return false
                    }
                }
            });
        })

        if (oksubmit){
            $.post(getRootPath_web()+"/evalmaster/evalIsFullscore",{
                cycledate:'${cycledate}'
            },function (data) {
                if (!data){
                    notFullTure = true;
                    oksubmit = true;
                }
                if (notFullTure && oksubmit){
                    var dialog = bootbox.dialog({
                        title: '满意度调查系统',
                        message: '<p><i class="fa fa-spin fa-spinner"></i> 请稍等...</p>',
                        closeButton: false
                    });
                    $.ajax({
                        type: 'POST',
                        url:getRootPath_web()+"/evalmaster/submitEvalMaster",
                        dataType:"json",
                        data:{
                            evalmasterjson:JSON.stringify($("#evaltable").bootstrapTable("getData")),
                            paperId:${paperId},
                            cycledate:'${cycledate}'
                        },
                        beforeSend:function(XMLHttpRequest){
                            $("#btn_save").attr("disabled",true);
                        },
                        success:function(data){
                            if (data){
                                dialog.modal('hide');
                                bootbox.alert("填报成功",function () {
                                    window.location.href= getRootPath_web()+"/deptMapper/selectDeptUpcomingPaperPage";
                                });
                            } else{
                                dialog.modal('hide');
                                bootbox.alert("填报失败");
                                $("#btn_save").attr("disabled",false);
                            }
                        }
                    }).fail(function (jqXHR, textStatus, errorThrown) {
                        bootbox.alert(jqXHR.responseJSON.message);
                        $("#btn_save").attr("disabled",false);
                    })
                } else if(!notFullTure){
                    bootbox.alert('不能全部满意');
                    $("#btn_save").attr("disabled",false);
                }
            },'json').fail(function (jqXHR, textStatus, errorThrown) {
                bootbox.alert(jqXHR.responseJSON.message);
            })
        }else{
            $("#btn_save").attr("disabled",false);
        }


    }

</script>


</body>
</html>
